home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-netbsd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-01  |  2.9 KB  |  119 lines

  1. /* fp-netbsd.c
  2.  * 
  3.  * Copyright (C) 2001 Jason Beegan
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <ieeefp.h>
  21. #include <gsl/gsl_ieee_utils.h>
  22. #include <gsl/gsl_errno.h>
  23.  
  24. int
  25. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  26. {
  27.   fp_except mode = 0;
  28.   fp_rnd    rnd  = 0;
  29.  
  30.   switch (precision)
  31.     {
  32.     case GSL_IEEE_SINGLE_PRECISION:
  33.       GSL_ERROR ("NetBSD only supports default precision rounding",
  34.          GSL_EUNSUP);
  35.       break;
  36.     case GSL_IEEE_DOUBLE_PRECISION:
  37.       GSL_ERROR ("NetBSD only supports default precision rounding",
  38.          GSL_EUNSUP);
  39.       break;
  40.     case GSL_IEEE_EXTENDED_PRECISION:
  41.       GSL_ERROR ("NetBSD only supports default precision rounding",
  42.          GSL_EUNSUP);
  43.       break;
  44.     }
  45.  
  46.   switch (rounding)
  47.     {
  48.     case GSL_IEEE_ROUND_TO_NEAREST:
  49.       rnd = FP_RN;
  50.       fpsetround (rnd);
  51.       break;
  52.     case GSL_IEEE_ROUND_DOWN:
  53.       rnd = FP_RM;
  54.       fpsetround (rnd);
  55.       break;
  56.     case GSL_IEEE_ROUND_UP:
  57.       rnd = FP_RP;
  58.       fpsetround (rnd);
  59.       break;
  60.     case GSL_IEEE_ROUND_TO_ZERO:
  61.       rnd = FP_RZ;
  62.       fpsetround (rnd);
  63.       break;
  64.     default:
  65.       rnd = FP_RN;
  66.       fpsetround (rnd);
  67.     }
  68.  
  69. /* Turn on all available exceptions apart from 'inexact'.
  70.    Denormalized operand exception not available on all platforms. */
  71.  
  72.   mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL;
  73. #ifdef FP_X_DNML
  74.   mode = mode | FP_X_DNML;
  75. #endif
  76.  
  77.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  78.     mode &= ~ FP_X_INV;
  79.  
  80.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  81.     {
  82. #ifdef FP_X_DNML
  83.       mode &= ~ FP_X_DNML;
  84. #endif
  85.     }
  86.   else
  87.     {
  88. #ifndef FP_X_DNML
  89.       GSL_ERROR ("NetBSD does not support the denormalized operand exception on this platform. "
  90.                  "Use 'mask-denormalized' to work around this.",
  91.                  GSL_EUNSUP);
  92. #endif
  93.     }
  94.  
  95.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  96.     mode &= ~ FP_X_DZ;
  97.  
  98.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  99.     mode &= ~ FP_X_OFL;
  100.  
  101.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  102.     mode &=  ~ FP_X_UFL;
  103.  
  104.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  105.     {
  106.       mode |= FP_X_IMP;
  107.     }
  108.   else
  109.     {
  110.       mode &= ~ FP_X_IMP;
  111.     }
  112.  
  113.   fpsetmask (mode);
  114.  
  115.   return GSL_SUCCESS;
  116.  
  117. }
  118.  
  119.